import request from '@/utils/request'

// ==================== 点赞相关 ====================

// 点赞帖子
export function likePost(postId) {
  return request({
    url: '/community/like/post/' + postId,
    method: 'post'
  })
}

// 取消点赞帖子
export function unlikePost(postId) {
  return request({
    url: '/community/like/post/' + postId,
    method: 'delete'
  })
}

// 获取帖子点赞状态
export function getPostLikeStatus(postId) {
  return request({
    url: '/community/like/post/' + postId + '/status',
    method: 'get'
  })
}

// 获取帖子点赞列表
export function getPostLikes(postId, pageReq) {
  return request({
    url: '/community/like/post/' + postId + '/list',
    method: 'get',
    params: pageReq
  })
}

// ==================== 评论相关 ====================

// 查询评论列表
export function listComments(query, pageReq) {
  return request({
    url: '/community/comment/list',
    method: 'post',
    data: query,
    params: pageReq
  })
}

// 根据帖子ID查询评论
export function getCommentsByPostId(postId, pageReq) {
  return request({
    url: '/community/comment/post/' + postId,
    method: 'get',
    params: pageReq
  })
}

// 查询评论详细
export function getComment(id) {
  return request({
    url: '/community/comment/' + id,
    method: 'get'
  })
}

// 新增评论
export function addComment(data) {
  return request({
    url: '/community/comment',
    method: 'post',
    data: data
  })
}

// 回复评论
export function replyComment(data) {
  return request({
    url: '/community/comment/reply',
    method: 'post',
    data: data
  })
}

// 修改评论
export function updateComment(data) {
  return request({
    url: '/community/comment',
    method: 'put',
    data: data
  })
}

// 删除评论
export function delComment(id) {
  return request({
    url: '/community/comment/' + id,
    method: 'delete'
  })
}

// 点赞评论
export function likeComment(commentId) {
  return request({
    url: '/community/like/comment/' + commentId,
    method: 'post'
  })
}

// 取消点赞评论
export function unlikeComment(commentId) {
  return request({
    url: '/community/like/comment/' + commentId,
    method: 'delete'
  })
}

// ==================== 收藏相关 ====================

// 收藏帖子
export function collectPost(postId) {
  return request({
    url: '/community/collect/post/' + postId,
    method: 'post'
  })
}

// 取消收藏帖子
export function uncollectPost(postId) {
  return request({
    url: '/community/collect/post/' + postId,
    method: 'delete'
  })
}

// 获取帖子收藏状态
export function getPostCollectStatus(postId) {
  return request({
    url: '/community/collect/post/' + postId + '/status',
    method: 'get'
  })
}

// 获取用户收藏列表
export function getUserCollections(pageReq) {
  return request({
    url: '/community/collect/user/list',
    method: 'get',
    params: pageReq
  })
}

// 批量取消收藏
export function batchUncollect(postIds) {
  return request({
    url: '/community/collect/batch/delete',
    method: 'delete',
    data: { postIds }
  })
}

// ==================== 举报相关 ====================

// 举报帖子
export function reportPost(data) {
  return request({
    url: '/community/report/post',
    method: 'post',
    data: data
  })
}

// 举报评论
export function reportComment(data) {
  return request({
    url: '/community/report/comment',
    method: 'post',
    data: data
  })
}

// 查询举报列表
export function listReports(query, pageReq) {
  return request({
    url: '/community/report/list',
    method: 'post',
    data: query,
    params: pageReq
  })
}

// 处理举报
export function handleReport(id, data) {
  return request({
    url: '/community/report/' + id + '/handle',
    method: 'put',
    data: data
  })
}